import axios from 'axios';
import {store} from '../store'
const request = axios.create({
    baseURL:"/api",
    timeout: 30000,
})

request.interceptors.request.use((config) => {
    const headers:any = {}
    const token = store.getState('token').token
    if(token) {
        headers.authorizations = token;
    }
    return {
        ...config,
        headers
    }
})

request.interceptors.response.use((response) => {
    console.log(response,'response')
    // {}
    return response.data
},(err)=>{
    if(err.response.status===401) {
        console.log('无权限 没登录')
        // 重定向到登录
        window.location.href='localhost:3000'
    }
})

export default request